<template>
  <div class="testing">
    <van-sticky>
      <van-nav-bar :title="$route.meta.title" left-arrow @click-left="onClickLeft" style="width:100%;" />
    </van-sticky>
    <van-tabs v-model="active" @click="onClick" title-active-color="#1bb89c" color="#1bb89c">
      <van-tab title="待审批" :name="2">
        <div class="testing-body">
          <div class="shop-list">
            <div class="lists">
              <div v-for="(item, index) in testingList" :key="index">
                <router-link :to="{path:'/testingDetail',query:{sid:item.id}}">
                  <van-cell :title="item.name" is-link :value="utype==0?item.spf_name:''" :border="false" center />
                </router-link>
              </div>
            </div>
          </div>
        </div>
        <van-empty description="暂无商品" v-if="testingList.length == 0" />
      </van-tab>
      <van-tab title="已通过" :name="1">
        <div class="testing-body">
          <div class="shop-list">
            <div class="lists">
              <div v-for="(item, index) in testingList" :key="index">
                <router-link :to="{path:'/testingDetail',query:{sid:item.id,index:0}}">
                  <van-cell :title="item.name" is-link :value="utype==0?item.spf_name:''" :border="false" center />
                </router-link>
              </div>
            </div>
          </div>
        </div>
        <van-empty description="暂无商品" v-if="testingList.length == 0" />
      </van-tab>
      <van-tab title="已拒绝" :name="3">
        <div class="testing-body">
          <div class="shop-list">
            <div class="lists">
              <div v-for="(item, index) in testingList" :key="index">
                <router-link :to="{path:'/testingDetail',query:{sid:item.id,index:0}}">
                  <van-cell :title="item.name" is-link :value="utype==0?item.spf_name:''" :border="false" center />
                </router-link>
              </div>
            </div>
          </div>
        </div>
        <van-empty description="暂无商品" v-if="testingList.length == 0" />
      </van-tab>
    </van-tabs>
  </div>
</template>
<script>
export default {
  name: "QualityTesting",
  data () {
    return {
      id: 0,
      utype: 0,
      spf_id: 0,
      showHot: 0,
      active: 0,
      testingList: [],
    };
  },
  methods: {
    onClickLeft () {
      this.$router.push({ name: 'controls' })
    },
    info (state) {
      this.$axios("/products/checkproductslist", {
        state: state, //审核状态（是否审核通过  1-通过，2-待审核，3-审核失败）
      })
        .then(res => {
          if (this.utype == 0) {
            this.testingList = res.data.data
          } else if (this.utype == 4) {
            this.testingList = res.data.data.filter(fn => {
              return fn.spf_id == this.spf_id
            })
          }
        })
        .catch((err) => {
          console.log(err);
        })
    },
    onClick (name) {
      this.info(name);
    },
  },
  created () {
    this.active = this.$route.query.active
    this.utype = JSON.parse(localStorage.getItem("userInfo")).user.utype
    this.spf_id = JSON.parse(localStorage.getItem("userInfo")).user.spf_id
    this.info(this.active || 2)
  },
}
</script>
<style lang="less" scoped>
.testing {
  display: flex;
  flex-direction: column;
  .shop-list {
    position: absolute;
    display: flex;
    flex-direction: column;
    width: 100%;
    background-color: #fff;
  }
  .lists {
    width: 100%;
    .custom-title {
      position: absolute;
      right: 55px;
    }
  }
  .lists-icon {
    z-index: 10;
  }
  .testing-body {
    display: flex;
  }
  .custom-title {
    color: #c2c2c2;
  }
  .ok {
    width: 70%;
    height: 30px;
    line-height: 30px;
    border-radius: 20px;
    text-align: center;
    color: #fff;
    background: rgb(255, 122, 33);
    margin: 20px auto 0;
  }
  .title {
    width: 100%;
    text-align: center;
    margin: 10px 0;
  }
  .flex {
    padding: 0 10px;
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
  }
  .img {
    width: 50px;
    height: 50px;
    margin-top: 10px;
    margin-right: 10px;
  }
  .popup {
    width: 300px;
    height: 400px;
    background: #fff;
  }
}
</style>
